package com.online.teaching.dao;
import com.online.teaching.pojo.Answer;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:admin
 * @Description:Answer的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface AnswerMapper extends Mapper<Answer> {
    /**
     * 教师删除一次作业
     * @param homeworkId
     * @return
     */
    @Select("UPDATE answer SET is_valid=0 WHERE homework_id=#{homework_id}")
    int teacherDeleteHomework(@ApiParam("homework_id") Integer homeworkId);

    /**
     * 根据作业id查询作答列表
     * @param homeworkId
     * @return
     */
    @Select("SELECT * FROM answer WHERE homework_id=#{homework_id} AND is_valid!=1")
    List<Answer>findAnswerList(@ApiParam("homework_id") Integer homeworkId);

    /**
     * 根据学生id以及作业id查询答案
     * @param stuId
     * @param homeworkId
     * @return
     */
    @Select("SELECT * from answer WHERE student_id=#{student_id} AND is_valid=1 AND homework_id=#{homework_id}")
    Answer findStudentAnswer(@ApiParam("student_id") Integer stuId,@ApiParam("homework_id") Integer homeworkId);
}
